package com.yxkj.syh.app.huarong.activities.links.detail;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

import com.syh.app.basic.base.view_model.BaseViewModel;
import com.syh.app.basic.utils.Tooast;
import com.syh.app.basic.utils.net.ApiObserver;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.yxkj.syh.app.huarong.bean.Linkman;
import com.yxkj.syh.app.huarong.bean.LinkmanResponse;
import com.yxkj.syh.app.huarong.data_center.model.CommonModel;

/**
 * 创建者：SYH
 * 时间：2020/6/4 15:51
 * 编辑者：SYH、
 * 标签：
 * 补充说明：
 */
public class LinkDetailVM extends BaseViewModel<ActivityEvent> {

    private Linkman linkman;

    public LinkDetailVM(@NonNull Application application) {
        super(application);
    }

    public ObservableField<String> ofForm1 = new ObservableField<>();
    public ObservableField<String> ofForm2 = new ObservableField<>();
    public ObservableField<String> ofForm3 = new ObservableField<>();
    public ObservableField<String> ofForm4 = new ObservableField<>();
    public ObservableField<String> ofForm5 = new ObservableField<>();

    private void setLinkman(Linkman linkman) {
        this.linkman = linkman;
        ofForm1.set(linkman.getName());
        ofForm2.set(linkman.getLinkman());
        ofForm3.set(linkman.getMobile());
        ofForm4.set(linkman.getArea());
        ofForm5.set(linkman.getAddress());
    }

    public void linkmanInfo(long id) {
        CommonModel.getCommonModel().linkInfo(id, mLifecycleProvider.bindToLifecycle(), new ApiObserver<LinkmanResponse>() {
            @Override
            public void onSuccess(LinkmanResponse linkmanResponse) {
                setLinkman(linkmanResponse.getData());
            }

            @Override
            public void onFailed(int code, String msg) {
                Tooast.warning(msg);
            }
        });
    }

}
